Make pictures for popups.
sbn <- b118cvsf %>% dplyr::pull(Subbasin_N)
for(i in 1:45){
ggplot2::ggsave(plot = data.frame(x = rnorm(100,0,1), y = rnorm(100,0,1)) %>%
ggplot(aes(x,y)) +
geom_point() +
geom_smooth() +
labs(title = sbn[i]) +
theme_minimal(),
filename = paste0("p_",i,".png"),
dpi = 200,
width = 2, height = 2)
}
b118cvsf %>%
leaflet(width = "100%") %>%
addProviderTiles(provider = "CartoDB.Positron") %>%
addPolygons(#label = ~ paste(as.character(Subbasin_N), fc),
# polygons
fillColor = ~ pal2(dry),
fillOpacity = 0.7,
smoothFactor = 1,
group = "Count of Dry Wells",
# lines
stroke = TRUE,
color = "#323232",
opacity = 1,
weight = 1,
popup =
paste0("<style> div.leaflet-popup-content {width:auto !important;}</style> <img src=/img/'","p_", 1:45,".png' width='1000' height='1000'>"),
options = popupOptions(closeButton = FALSE)
) %>%
addPolygons(#label = ~ paste(as.character(Subbasin_N), fc),
# polygons
fillColor = ~ pal(frp),
fillOpacity = 0.7,
smoothFactor = 1,
group = "Failure Ratio",
# lines
stroke = TRUE,
color = "#323232",
opacity = 1,
weight = 1,
popup =
paste0("<style> div.leaflet-popup-content {width:auto !important;}</style> <img src='","p_", 1:45,".png' width='1000' height='1000'>"),
options = popupOptions(closeButton = FALSE)
) %>%
addAwesomeMarkers(lng = domcv5ll@coords[, 1],
lat = domcv5ll@coords[, 2],
popup = paste("Well ID:", domcv5ll$WCRNumber,"<br>",
"(", domcv5ll$lon, "N", domcv5ll$lat, "W)", "<br>",
"Bottom of Perforated Interval:", domcv5ll$bot, "ft.", "<br>",
"Dry:", domcv5ll$dry),
icon = icons,
group = "Wells",
clusterOptions = markerClusterOptions()) %>%
addLegend("topright",
pal = pal,
layerId = "t",
values = ~ frp,
opacity = 1,
title = "% Failure",
group = "Failure Ratio",
labFormat = function(type, cuts, p) {
n = length(cuts)
paste0(cuts[-n], " – ", cuts[-1])
}
) %>%
addLegend("bottomright",
pal = pal2,
values = ~ dry,
opacity = 1,
title = "Count of Dry Wells",
group = "Count of Dry Wells",
labFormat = function(type, cuts, p) {
n = length(cuts)
paste0(cuts[-n], " – ", cuts[-1])
}
) %>%
addLayersControl(overlayGroups = c("Count of Dry Wells", "Failure Ratio", "Wells"),
position = "topleft",
options = layersControlOptions(collapsed = FALSE)) %>%
hideGroup(c("Failure Ratio","Wells")) %>%
addEasyButton(easyButton(
icon="fa-globe", title="Zoom to Level 7",
onClick=JS("function(btn, map){ map.setZoom(7); }"))) %>%
addEasyButton(easyButton(
icon="fa-crosshairs", title="Locate Me",
onClick=JS("function(btn, map){ map.locate({setView: true}); }")))